﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using log4net;
using System.Reflection;

namespace SopCastRecorder
{
	public partial class ErrorForm : Form
	{
		private static ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

		public ErrorForm()
		{
			InitializeComponent();
			this.Init();
		}

		private void Init()
		{
			try
			{
				this.Init2();
			}
			catch (Exception exception1)
			{
				logger.Error(MethodBase.GetCurrentMethod().Name, exception1);
				Form1.SetErrorStatus();
			}
		}

		private void Init2()
		{
			this.textBox1.Text = string.Empty;
			for (var i = 0; i < Log4NetManager.LogFilePaths.Count(); i++ )
			{
				this.AppendTextBox(Log4NetManager.LogFilePaths[Log4NetManager.LogFilePaths.Length -1 - i]);
			}
		}

		private void AppendTextBox(string path)
		{
			if (!File.Exists(path))
			{
				return;
			}

			try
			{
				FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
				using (var reader = new StreamReader(fs, Encoding.Unicode))
				{
					this.textBox1.AppendText(reader.ReadToEnd());
					reader.Close();
				}
			}
			catch
			{
			}
		}
	}
}
